import Vue from 'vue'
import VueRouter from 'vue-router'
import {
  Dialog
} from 'vant'

Vue.use(VueRouter)

const routes = [
  // 路由重定向
  {
    path: '/',
    redirect: '/user'
  },
  // 授权登录
  {
    path: '/login',
    name: 'Login',
    component: () => import('@/views/Login')
  },
  // 首页
  {
    path: '/user',
    name: 'User',
    meta: {
      keepAlive: true
    },
    component: () => import('@/views/User')
  },
  // 充值
  {
    path: '/recharge',
    name: 'Recharge',
    component: () => import('@/views/Recharge')
  },
  // 充值成功
  {
    path: '/rechargeSuccess',
    name: 'RechargeSuccess',
    component: () => import('@/views/RechargeSuccess')
  },
  // 战绩详情
  {
    path: '/gameDetail',
    name: 'GameDetail',
    component: () => import('@/views/GameDetail')
  },
  // 视频
  {
    path: '/video',
    name: 'Video',
    meta: {
      keepAlive: true
    },
    component: () => import('@/views/Video')
  },
  // 排行榜 PC
  {
    path: '/rankPC',
    name: 'RankPC',
    component: () => import('@/views/RankPC')
  }
]

const router = new VueRouter({
  routes,
  scrollBehavior(to, from, savedPosition) {
    return {
      x: 0,
      y: 0
    }
  }
})

// 挂载路由导航守卫
// router.beforeEach((to, from, next) => {
//   if (to.path === '/login') {
//     return next()
//   }
//   if (!window.localStorage.getItem('token')) {
//     return next('/login')
//   }
//   next()
// })

export default router
